package com.souku.finance.application.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.manager.RequestManager;
import com.souku.finance.application.R;
import com.souku.finance.application.base.BaseActivity;
import com.souku.finance.application.bean.UserAccMoreBean;
import com.souku.finance.application.http.UrlConstact;
import com.souku.finance.application.http.volley.ReqListener;
import com.souku.finance.application.http.volley.SuccessError;
import com.souku.finance.application.ui.more.BankCard2Activity;
import com.souku.finance.application.utils.JsonUtil;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.utils.ParamUtil;
import com.souku.finance.application.utils.ToastUtil;
import com.souku.finance.application.utils.ViewUtil;

import java.util.HashMap;

import butterknife.BindView;

/**
 * Created by Android on 2016/12/19.
 */

public class WithDrawActivity extends BaseActivity implements View.OnClickListener {

    protected RelativeLayout topBack;
    protected TextView topTitle;
    protected EditText etBankcard;
    protected ImageView ivDelet;
    protected Button btnOk;
    LinearLayout llCard;
    TextView tvMoney;
    TextView tvCard;

    @Override
    public void internet() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.act_withdraw);
        initView();
        topTitle.setText("提现");
        ViewUtil.setDelete(etBankcard, ivDelet, null);

        getUserAccMore();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_back) {
            onBackPressed();
        } else if (view.getId() == R.id.btn_ok) {
            String amount = etBankcard.getText().toString();
            Intent intent = new Intent(this, WithDrawWebActivity.class);
            intent.putExtra("amount", amount);
            startActivity(intent);
        }else if (view.getId() == R.id.tv_card){
            Intent intent = new Intent(this, BankCard2Activity.class);
            startActivity(intent);
        }
    }

    private void initView() {
        topBack = (RelativeLayout) findViewById(R.id.top_back);
        topBack.setOnClickListener(WithDrawActivity.this);
        topTitle = (TextView) findViewById(R.id.top_title);
        etBankcard = (EditText) findViewById(R.id.et_bankcard);
        ivDelet = (ImageView) findViewById(R.id.iv_delet);
        btnOk = (Button) findViewById(R.id.btn_ok);
        tvMoney = (TextView) findViewById(R.id.tv_money);
        tvCard = (TextView) findViewById(R.id.tv_card);
        llCard = (LinearLayout) findViewById(R.id.ll_card);
        btnOk.setOnClickListener(WithDrawActivity.this);
        tvCard.setOnClickListener(WithDrawActivity.this);
    }

    private void getUserAccMore() {
        HashMap<String, String> map = ParamUtil.getParams();
        RequestManager.getInstance().post(UrlConstact.USER_ACC_MORE, ParamUtil.getSing(map), new ReqListener(WithDrawActivity.this, new SuccessError() {
            @Override
            public void onSuccess(String response) {
                if (JsonUtil.getCode(response) == 1) {
                    UserAccMoreBean bean = JsonUtil.fastBean(JsonUtil.getData(response).toString(), UserAccMoreBean.class);
                    tvMoney.setText(MyTextUtil.setMoneyToElement(bean.getMoney()));
                } else {
                    ToastUtil.show(JsonUtil.getMessage(response));
                }
            }

            @Override
            public void onError(String errorMsg) {
                ToastUtil.show("网络错误");
            }
        }), ParamUtil.getHeaders());
    }
}
